﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hinacom.Scheduler.Service.SchedulerService;
using System.ServiceModel;
using System.Configuration;
using System.ServiceModel.Configuration;
using System.ServiceModel.Channels;
using System.IO;

namespace Hinacom.Scheduler.Service.Proxy
{
    public class SchedulerProxy
    {
        public SchedulerProxy()
        {
            this.client = new SchedulerServiceClient();
        }
        public SchedulerProxy(string remoteAddress)
        {
            Binding binding = new BasicHttpBinding()
            {
                Name = "BasicHttpBinding_ISchedulerService"
            };
            EndpointAddress endpoint = new EndpointAddress(remoteAddress);
            this.client = new SchedulerServiceClient(binding, endpoint);
        }
        public SchedulerProxy(string endpointConfigurationName, string remoteAddress)
        {
            this.client = new SchedulerServiceClient(endpointConfigurationName, remoteAddress);
        }

        private SchedulerServiceClient client;

        public void CreateJob(JobInfo jobInfo)
        {
            client.CreateJob(jobInfo, false);
        }
        public void EditJob(JobInfo jobInfo)
        {
            client.CreateJob(jobInfo, true);
        }
        public IEnumerable<JobInfo> GetActiveJobs()
        {
            return client.GetActiveJobs();
        }

        public void DeleteJob(string jobname, string group)
        {
            client.DeleteJob(jobname, group);
        }

        public IEnumerable<JobHistory> GetJobHistories(string jobName, string jobGroup, int? lastLoadedId = null)
        {
            return client.GetJobHistories(jobName, jobGroup, lastLoadedId);
        }
        public string GetHistoryLog(int historyId)
        {
            return client.GetJobHistoryLog(historyId);
        }
    }
}
